#include "StringUtils.h"

vector<string> StringUtils::split(const string& str, const string& delim) {
    vector<string> tokens;

    int index = 0;
    int lastIndex = 0;
    while ((index = str.find(delim, lastIndex)) != str.npos) {
        tokens.push_back(str.substr(lastIndex, index - lastIndex));
        lastIndex = index + delim.size();
    }
    tokens.push_back(str.substr(lastIndex));

    return tokens;
}

int StringUtils::toInt(const string& str) throw(NumberFormatException) {
    int n = atoi(str.c_str());
    if (n == 0 && str != "0") {
        throw NumberFormatException(str);
    }

    return n;
}